<extend name="Public/Info/Common"/>

<block name="pageContent">
    <div class="bjui-pageContent">
        <form action="{:U('updateHook')}" class="pageForm" data-toggle="validate" method="post">
            <!-- 菜单id号 -->
            <input type="hidden" name="id" value="{:I('get.id')}">
            <table class="table table-condensed table-hover">
                <tbody>
                <tr>
                    <td>
                        <label class="control-label">钩子名称：（需要在程序中先添加钩子，否则无效）</label>
                    </td>
                    <td>
                        <input type="text" name="name" value="{$data.name}" data-rule="required"
                               size="20">
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="control-label">钩子描述：（钩子的描述信息）</label>
                    </td>
                    <td>
                        <input type="text" name="description" value="{$data.description}" data-rule="required"
                               size="20">
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="control-label">钩子类型：（区分钩子的主要用途）</label>
                    </td>
                    <td>
                        <select name="type" data-toggle="selectpicker">
                            <volist name=":C('HOOKS_TYPE')" id="vo">
                                <option value="{$key}" <eq name="data.type" value="$key"> selected</eq>>{$vo}</option>
                            </volist>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <present name="data">
                            <div class="form-item cf">
                                <label class="item-label">钩子挂载的插件排序<span class="check-tips">（拖动后保存顺序，影响同一个钩子挂载的插件执行先后顺序）</span></label>
                                <div class="controls">
                                    <input type="hidden" name="addons" value="{$data.addons}" readonly>
                                    <empty name="data.addons">
                                        暂无插件，无法排序
                                        <else />
                                        <ul id="sortUl" class="dragsort">
                                            <volist name=":explode(',',$data['addons'])" id="addons_vo">
                                                <li class="getSort"><b>&times;</b><em>{$addons_vo}</em></li>
                                            </volist>
                                        </ul>
                                        <script type="text/javascript">
                                            $(function(){
                                                $("#sortUl").dragsort({
                                                    dragSelector:'li',
                                                    placeHolderTemplate: '<li class="draging-place">&nbsp;</li>',
                                                    dragEnd:function(){
                                                        updateVal();
                                                    }
                                                });

                                                $('#sortUl li b').click(function(){
                                                    $(this).parent().remove();
                                                    updateVal();
                                                });

                                                // 更新排序后的隐藏域的值
                                                function updateVal() {
                                                    var sortVal = [];
                                                    $('#sortUl li').each(function(){
                                                        sortVal.push($('em',this).text());
                                                    });
                                                    $("input[name='addons']").val(sortVal.join(','));
                                                }
                                            })
                                        </script>
                                    </empty>
                                </div>
                            </div>
                        </present>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
</block>
